package web.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import web.mapper.ClassScheduleMapper;
import web.pojo.ClassSchedule;

@Service
public class ClassScheduleService {

    @Autowired
    ClassScheduleMapper mapper;

    public List<ClassSchedule> fetchScheduleByWeekAndStudent(Integer week, Long teacher_id, Long id) {
        try {
            return mapper.fetchScheduleByWeekAndStudent(week, teacher_id, id);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }

    public List<ClassSchedule> fetchScheduleByWeekAndTeacher(Integer week, Long id) {

        try {
            return mapper.fetchScheduleByWeekAndTeacher(week, id);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new ArrayList<>();
        }
    }

    public boolean insertSchedule(Long courseId, Long classId,
            Long teacherId, Long classRoomId, String[] week,
            Integer day, Integer section) {

        try {
            mapper.insertSchedule(courseId, classId, teacherId, classRoomId, week, day, section);
            return true;
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;
        }
    }

    public List<ClassSchedule> fetchScheduleList(Long teacherId, Long courseId,
            Long classId, Long classroomId, Integer week) {
        try {
            return mapper.fetchScheduleList(teacherId, courseId, classId, classroomId, week);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return new ArrayList<>();
        }
    }

    public boolean deleteScheduleItemById(Long id) {
        try {
            mapper.deleteSchedule(id);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public boolean updateSchedule(Long id, Long teacherId, Long classroomId, Integer week, Integer day,
            Integer section) {
        try {
            mapper.updateSchedule(id, teacherId, classroomId, week, day, section);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

}
